package com.example.emp20221871luhaotian.demos.mapper;

import com.example.emp20221871luhaotian.demos.po.Emp;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author lht
 * @version 1.0
 * @since 2025/6/3
 */
@Mapper
public interface EmpMapper {

    @Insert("INSERT INTO emp(name, deptName, firstSal, secondSal) VALUES(#{name}, #{deptName}, #{firstSal}, #{secondSal})")
    int insertEmp(Emp emp);

    @Select("SELECT * FROM emp")
    List<Emp> findAllEmp();

    @Select("SELECT deptName, SUM(firstSal) as firstSal, SUM(secondSal) as secondSal FROM emp GROUP BY deptName")
    List<Map<String, Object>> getAllSalary();

    @Update("UPDATE emp SET name=#{name}, deptName=#{deptName}, firstSal=#{firstSal}, secondSal=#{secondSal} WHERE id=#{id}")
    int updateEmp(Emp emp);

    @Delete("DELETE FROM emp WHERE id=#{id}")
    int deleteById(Integer id);

    @Select("SELECT * FROM emp WHERE id=#{id}")
    Emp findEmpById(Integer id);


}
